<template>
	<div id="creditsExchange" class="creditsExchange same-change-oldstyle">
		<div class="same-head-box">
			<div class="saem-seat-box">
				<div class="saem-seat-left">
					<span>当前位置：</span>
					<el-breadcrumb separator-class="el-icon-arrow-right">
						<el-breadcrumb-item>经营管理</el-breadcrumb-item>
						<el-breadcrumb-item>积分兑换</el-breadcrumb-item>
					</el-breadcrumb>
				</div>
				<div class="saem-seat-right">
					<button class="same-search-btns same-search-export" @click="RefreshFun">刷新</button>
					<!-- <button class="same-search-btns" @click="returnBack">返回</button> -->
				</div>
			</div>
		</div>
		<div class="headtx_box same-table-box">
			<div class="balance">账户积分 <span class="balspan">{{userinfo.integral}}</span> 分
				<el-button type="primary" style="margin-left: 10px;" size="small" @click="jumpintegral" disabled>暂不开放</el-button>
				<!-- <button class="btn_style_b"
					@click="jumpintegral" type="button" disabled>暂不开放</button>
				-->
			</div>
			<h4 class="same-title-box">
				数据统计
			</h4>

			<div class="same-search-box">
				<div>
					<div class="same-search-left">
						<div class="same-left-one">
							<span class="same-search-span same-search-fisrt">申请时间：</span>
							<el-date-picker style="width:140px" v-model="date1" type="date" size="medium" value-format="yyyy-MM-dd"
								placeholder="开始日期">
							</el-date-picker>
							<div class="same-interval">至</div>
							<el-date-picker style="width:140px" v-model="date2" type="date" size="medium" value-format="yyyy-MM-dd"
								placeholder="结束日期">
							</el-date-picker>
						</div>
						<div class="same-left-one" v-if="!moveShow">
							<div class="same-left-zdshwo" :hidden="!moveBtn" @click="openMore">更多查询条件<i
									:class="[moveShow?'el-icon-arrow-up':'el-icon-arrow-down']"></i></div>
							<el-button type="primary" size="medium" @click="findJfList()">搜索</el-button>
							<el-button type="info" size="medium" @click="reset()">重置</el-button>
						</div>
					</div>
				</div>
				<!-- 更多搜索 -->
				<div>
					<div class="same-search-left new-sear-height" ref="leftHeight">
						<div class="same-left-one">
							<span class="same-search-span">订单类型：</span>
							<el-select size="medium" v-model="type" placeholder="请选择" style="width: 140px;">
								<el-option v-for="item in stateoption" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</div>
						<div class="same-left-one" :class="[moveShow?'':'new-sear-opacity']">
							<div class="same-left-zdshwo" :hidden="!moveBtn" @click="openMore">收起更多查询条件<i
									:class="[moveShow?'el-icon-arrow-up':'el-icon-arrow-down']"></i></div>
							<el-button type="primary" size="medium" @click="findJfList()">搜索</el-button>
							<el-button type="info" size="medium" @click="reset()">重置</el-button>
						</div>
					</div>
				</div>
			</div>

			<div class="table_box">

				<div class="common-table-outer">
					<el-table class="common-table" v-loading="loading" header-cell-class-name="common-table-header-cell"
						:data="tableData" stripe>
						 <el-table-column header-align="center" width="70" align="center" label="序号">
							<template slot-scope="scope">
								{{scope.$index+1+(currentPage-1)*row}}
							</template>
						</el-table-column>
						<el-table-column align="center" prop="add_time" label="申请时间">
						</el-table-column>
						<el-table-column align="center" prop="s_num" label="兑换积分数">
						</el-table-column>
						<el-table-column align="center" prop="type" label="类型">
						</el-table-column>
						<el-table-column align="center" label="备注">
							<template slot-scope="scope">
								{{scope.row.remarks || '——'}}
							</template>
						</el-table-column>
						<template slot="empty" v-if="isLoad">
							<div class="new-no-data-show">
								<img src="../../assets/images/no-data.png" alt="">
								<div>暂无相关数据</div>
							</div>
						</template>
					</el-table>
					<div class="same-page-inShow" v-if="tableData.length>0 && isLoad">
						<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
							:current-page="currentPage" :page-sizes="sizes" :page-size="row"
							layout="total,prev, pager, next, jumper, sizes" :total="total">
						</el-pagination>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	export default {
		name: 'creditsExchange',
		data: function () {
			return {
				loading: false,
				row: 15,
				sizes: [15, 30, 40, 50],
				total: 0,
				currentPage: 1,
				tableData: [], // 返回的结果集合
				time: '', // 结束时间
				type: '', //选择类别
				stateoption: [{
					value: '',
					label: '全部'
				}, {
					value: '1',
					label: '获得'
				}, {
					value: '2',
					label: '支出'
				}],
				userinfo: [],
				date1: '',
				date2: '',
				isLoad: false,

				moveBtn: false,//是否暂时更多查询条件按钮按钮 搜索条件控制
				moveShow: false,//是否开启动画
				scrollHeight: '',//需要监听的高度
			}
		},
		computed: {

		},
		// 初始化执行
		created: function () {
			this.$emit('gitHidden', true);//是否隐藏底部版权 true 隐藏 
			this.getPartner();
			this.integralList(); // 获取积分管理页面数据
		},
		inject: [
			'reload'
		],
		methods: {
			RefreshFun() {
				// 调用reload方法，刷新整个页面
				this.reload()
			},
			//返回
			returnBack() {
				this.$router.back(-1);
			},
			//获取合伙人信息
			getPartner() {
				var that = this;
				that.$post({
					url: 'Partner/Setup/get_partner',
					data: {

					},
					success: function (data) {
						that.userinfo = data.data;
					}

				})
			},
			//跳转积分兑换
			jumpintegral() {
				this.$router.push({
					path: '/integralExchange'
				})
			},
			//重置
			reset() {
				this.date1 = "";
				this.date2 = "";
				this.type = "";
				this.currentPage = 1;
				this.integralList();
			},
			//搜索
			findJfList() {
				this.currentPage = 1;
				this.integralList();
			},
			//每页
			handleSizeChange(val) {
				this.currentPage = 1;
				this.row = val;
				this.integralList();
			},
			//分页
			handleCurrentChange(val) {
				this.currentPage = val;
				this.integralList();
			},
			// 获取积分管理页面数据
			integralList: function () {
				this.loading = true; //打开loading动画
				this.isLoad = false; //是否加载
				var that = this;
				// ajax请求
				that.$post({
					url: 'Partner/Achievement/convertibilityList',
					data: {
						page: that.currentPage,
						row: that.row,
						start_time: that.date1 ? that.date1 : '',
						end_time: that.date2 ? that.date2 : '',
						type: that.type
					},
					success: (data) => {
						this.isLoad = true;
						this.loading = false; //关闭动画
						if (data.code == 1000) {
							that.tableData = data.data.data;
							that.total = Number(data.data.page.total_number);
							that.currentPage = data.data.page.current_page;
						}
					}
				})
			},
			//此处获取高度必须在dom元素创建完成之后才能获取
			gitHeight() {
				//  let clientHeight=this.$refs.leftHeight.clientHeight;
				let scrollHeight = this.$refs.leftHeight.scrollHeight;
				this.scrollHeight = scrollHeight;
				scrollHeight <= 30 ? this.moveBtn = false : this.moveBtn = true;

			},
			openMore() {
				this.moveShow = !this.moveShow;
				this.$refs.leftHeight.style.height = this.moveShow ? this.scrollHeight + 'px' : 0 + 'px';
			},
		},
		mounted() {
			this.gitHeight();
			//监听高度变化
			var that = this;
			window.addEventListener("resize", function () {
				let scrollHeight = that.$refs.leftHeight && that.$refs.leftHeight.scrollHeight ? that.$refs.leftHeight.scrollHeight : that.scrollHeight;
				that.scrollHeight = scrollHeight;
			});
		},
		watch: {
			// 如果 `scrollHeight` 发生改变，这个函数就会运行 此处是为了防止用户缩小屏幕导致页面显示不全
			scrollHeight: function (val) {
				this.$refs.leftHeight.style.height = this.moveShow ? this.scrollHeight + 'px' : 0 + 'px';
			}
		}
	}
</script>
<style scoped>
	#creditsExchange {
		width: 100%;
		height: 100%;
		background: #fff;
	}

	#creditsExchange .same-title-box {
		padding: 15px 0;
	}

	/* 头部搜索 */

	.headtx_box {
		display: flex;
		flex-direction: column;
		padding-top: 0 !important;
	}

	#creditsExchange .same-search-box {
		padding-top: 0 !important;
	}

	.balance {
		padding-top: 20px;
	}

	#creditsExchange .balance .btn_style_b {
		border: none;
		width: 70px;
		height: 30px;
		color: #fff;
		font-weight: bold;
		font-size: 14px;
		background: #275485;
		margin-left: 40px;
		border-radius: 4px;
	}

	.balspan {
		color: #FF6565;
		font-weight: bold;
		font-size: 22px;
	}
</style>
